package com.cn.hu.redis.study;

import static org.junit.Assert.*;

import org.apache.log4j.Logger;
import org.junit.Test;

import redis.clients.jedis.Jedis;

public class Demo1Impl implements Demo {
	
	Logger logger = Logger.getLogger(Demo1Impl.class);
	//定义REDIS服务器IP地址
	String host = "127.0.0.1";
	//定义REDIS服务器端口号
	int port = 6379;
	//实例化JEDIS对象，传入地址和端口
	Jedis client = new Jedis(host, port);
	
	@Override
	public boolean get_illleagal(final int no,final String host) {
		Jedis client = new Jedis(host, 6379);
		String key = host+":"+no;
		String value = client.get(key);
		if (value==null) {
			client.set(key,"1");
			client.expire(key, 60);
			client.close();
			return true;
		}
		else if(Integer.parseInt(value)<11){
			client.incr(key);
			client.close();
			return true;
		}
		else{
			client.close();
			return false;
		}
	}
	
	@Test
	public void testName() throws Exception {
		for (int i = 0; i < 100; i++) {
			 logger.debug(i+"-----------"+get_illleagal(1, "127.0.0.1"));
			
		}
	}

}
